<?php
/**
 * 控制账号单点登录
 * User: Administrator
 * Date: 2019/2/26 0026
 * Time: 0:13
 */

namespace app\Lib\Model\User;


use app\Lib\Exception\BlException;
use app\Lib\InterfaceIn\User\UserHandle;

class ValidateLogin
{
    private $key = 'userLogin';
    private $userToken;
    private $userClass;
    public function __construct(UserHandle $userClass,$userToken)
    {
        $this->userClass = $userClass;
        $this->userToken = $userToken;
    }
    /**
     * 获取用户的登录key
     * @return string
     */
    private function getUserLoginKey(){
//        throw new BlException($this->key.'_'.$this->userClass->getUid());
        return  md5($this->key.'_'.$this->userClass->getUid());
    }

    public function  run(){
        $keyCache  =  $this->getUserLoginKey();
        $userToken =  cache($keyCache);
        if($userToken != $this->userToken){
            return false;
        }
        return true;
    }



}